package com.example.administrator.waitan.find.news.newscontent;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.example.administrator.waitan.R;
import com.example.administrator.waitan.base.BaseActivity;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/1/19.
 */
public class NewsContentActivity extends BaseActivity {
    private ListView mListView;
    private NewsContentBaseAdapter mAdapter;
    private List<String> images;
    private RequestQueue queue;
    private String url = "http://api.alithefox.net/comics/";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news_content);
        mListView = (ListView) findViewById(R.id.lv_news_content);
        findViewById(R.id.btn_news_content_return).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        final TextView textView = (TextView) findViewById(R.id.tv_news_content_title);
        Intent receiveId = getIntent();
        String receive = receiveId.getStringExtra("Id");
        String contentUrl = url + receive;
        Log.d("new",contentUrl);
        queue = Volley.newRequestQueue(this);
        StringRequest request = new StringRequest(contentUrl, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Gson gson = new Gson();
                images = new ArrayList<>();
                NewsContentBeans beans = gson.fromJson(response, NewsContentBeans.class);
                NewsContentData data = beans.getData();
                textView.setText(data.getTitle());
                for (int i = 0; i < data.getImages().size(); i++) {
                    images.add(data.getImages().get(i).getF());
                }
                mAdapter = new NewsContentBaseAdapter(images,NewsContentActivity.this);
                mListView.setAdapter(mAdapter);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        queue.add(request);
    }
}
